#pragma once

#include "Deployment.h"

#include "DeployedArtifact.h"
#include "DeploymentSpecification.h"
#include "DeploymentTarget.h"

namespace uml {

Deployment::Deployment(const QString& umlType)
    : Dependency(umlType) {}

void Deployment::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    Dependency::fromJson(json, errorList);
    JsonSerializable::fromJsonArray(configurations_, "configurations", json, errorList);
    JsonSerializable::fromJsonArray(deployedArtifacts_, "deployedArtifacts", json, errorList);
    location_ = JsonSerializable::create<DeploymentTarget>(json.value("location"), errorList);

}

void Deployment::toJson(QJsonObject& json) {
    Dependency::toJson(json);
    JsonSerializable::toJsonArray(configurations_, "configurations", json);
    JsonSerializable::toJsonArray(deployedArtifacts_, "deployedArtifacts", json);
    if (location_) {
        QJsonObject location_json;
        location_->toJson(location_json);
        json.insert("location", location_json);
    }
}

/// <summary>
/// configurations getter
/// The specification of properties that parameterize the deployment and execution
/// of one or more Artifacts.
/// </summary>
vector<shared_ptr<DeploymentSpecification>>& Deployment::configurations() {
    return configurations_;
}

/// <summary>
/// deployedArtifacts getter
/// The Artifacts that are deployed onto a Node. This association specializes the
/// supplier association.
/// </summary>
vector<shared_ptr<DeployedArtifact>>& Deployment::deployedArtifacts() {
    return deployedArtifacts_;
}

/// <summary>
/// location getter
/// The DeployedTarget which is the target of a Deployment.
/// </summary>
shared_ptr<DeploymentTarget> Deployment::location() const {
    return location_;
}

/// <summary>
/// location setter
/// The DeployedTarget which is the target of a Deployment.
/// </summary>
void Deployment::setLocation(shared_ptr<DeploymentTarget> value) {
    location_ = value;
}

} // namespace uml
